﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JYH.Data;
using Newtonsoft.Json;
using JYH.Model;
using JYH.DataAccess;
using JYH.Framework;
using System.ComponentModel;

namespace JYH.Business
{
    /// <summary>
    ///  SysMessageInfo
    /// </summary>
    public class SysMessageInfoBLL : BusinessBase<SysMessageInfo>
    {
        /// <summary>
        ///  SysMessageInfo
        /// </summary>
        public SysMessageInfoBLL()
        {
            myDataBase = DB.D();
            this.SqlSelect = @"; Select SysMessageInfo.* From SysMessageInfo";
        }

        /// <summary>
        /// 获取单个信息提示
        /// </summary>
        /// <param name="MessageNO">信息编号</param>
        /// <returns></returns>
        public static string GetMessageInfo(string MessageNO)
        {
            try
            {
                Sql sql = new Sql();
                sql.Append(@"; Select SysMessageInfo.* From SysMessageInfo");
                sql.Append("Where SysMessageInfo.MessageNO='" + SqlFilterHelper.Filter(MessageNO) + "'");
                Database db = DB.D();
                SysMessageInfo Info = db.SingleOrDefault<SysMessageInfo>(sql);
                if (Info == null)
                {
                    return "Please contact the system service provider.";
                }
                else
                {
                    return Info.Message;
                }
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 获取所有消息
        /// </summary>
        /// <returns></returns>
        public static List<SysMessageInfo> GetSysMessages()
        {
            string Msg = string.Empty;
            try
            {
                Sql sql = new Sql();
                sql.Append(@"; Select SysMessageInfo.* From SysMessageInfo");
                sql.Append("Where 1=1");
                sql.OrderBy("SysMessageInfo.MessageNO");
                Database db = DB.D();
                return db.Fetch<SysMessageInfo>(sql);
            }
            catch
            {
                return null;
            }
        }
    }
}